﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MISAPP.Classify.DataAccess
{
   
    public class DA_Presentation:DA_Matrix
    {
      
        public DA_Presentation()
        {
            tableName = "Presentation";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="p_misGroup"></param>
        /// <param name="p_user_id"></param>
        /// <param name="p_fileName"></param>
        /// <param name="p_count"></param>
        /// <param name="p_type">1:經委會2:審委會</param>
        /// <returns></returns>
        public bool Insert(string p_misGroup,string p_user_id,string p_fileName
            , string p_count, string p_type)
        {
            string sql = @"
INSERT INTO Presentation (MISGroup,user_id,init_time,ppt,PPTCount,PPTType)
VALUES(@MISGroup,@user_id,GETDATE(),@ppt,@pptCount,@p_type)
";
            FillTableSchema(tableName);
            whereList = new List<string>();
            fieldList = new List<field>();
            
            FillFieldList(new string[] { p_misGroup }, new string[] { "@MISGroup" }, "MISGroup");
            FillFieldList(new string[] { p_user_id }, new string[] { "@user_id" }, "user_id");
            FillFieldList(new string[] { p_fileName }, new string[] { "@ppt" }, "PPT");
            FillFieldList(new string[] { p_count }, new string[] { "@pptCount" }, "PPTCount");
            FillFieldList(new string[] { p_type }, new string[] { "@p_type" }, "PPTType");

            AddParameter(sql);
            int iResult = Common.DAL.ExecuteNoneQuery(cmd);
            return iResult < 0 ? false : true;
        }

        public DataTable GetData(string p_type)
        {
            string sql = string.Format(@"
SELECT 
	*
FROM(
    SELECT
     *
     ,ROW_NUMBER() OVER(PARTITION BY A.MISGroup ORDER BY A.INIT_Time DESC) AS SEQ
     FROM [Presentation] AS A 
     WHERE PPTCOUNT > 0 AND PPTType='{0}'
)A
WHERE A.SEQ = 1
",p_type);
            return getData(sql, "PPT");
        }

        public DataTable GetSquaredAreaByLevel(string p_level)
        {
            return Utility.GetParameterByLevel("Presentation", p_level);
        }

        public DataTable GetSquaredAreaByLevel(string p_level, string p_team)
        {
            //return GetSquaredAreaByLevel(p_team, p_level);
            return Utility.GetParameterByLevel(p_team, p_level);
        }
    }
}
